{% extends 'sign_in.html' %}
{% load staticfiles %}

{#设置页面说明#}
{% block page_tittle %}
<h4>用户注册</h4>
{% endblock page_tittle %}

{#去掉'用户注册'#}
{% block sign_up_a %}
    <span class="warn "></span>
{% endblock sign_up_a %}

{#点击注册#}
{% block register %}
    <input class="sub" type="submit" value="注册">
{% endblock %}
<script src="{% static 'js/jquery-3.4.1.js' %}"></script>
{% block script %}

<script>
    {# 注册   #}
    $('.sub').click(function () {
        $.post(
            '{% url 'sign_up' %}',
            {username: $('[name="username"]').val(), password: $('[name="password"]').val()},
            function (response) {
               if (response.includes('用户已存在')) {
                   $('.warn').text(response).css('color', 'red')
               }
               else {
                   $('.warn').text(response).css('color', '#20A3F5');
                   window.location.href='{% url 'home' %}'
               }
            }
        );
    });

    $('[name="username"]').focus(function () {
        $('.warn').text('')
    })
</script>
{% endblock script %}
